<?php
namespace app\api\controller;

use think\Controller;

class Base extends Controller
{
    // 入口KEY值
    protected $accessKey;
    // 分页参数
    protected $page;
    // 当前时间戳
    protected $timeStamp;
    // 用户ID信息 - admin_id, user_id
    protected $accessData;
    // 加密KEY
    protected $signKey;

    public function _initialize ()
    {
        $this->accessKey = config('custom.accessKey');
        $this->signKey = config('custom.signKey');
        $this->page = 50;
        $this->timeStamp = time();
        
        header('Access-Control-Allow-Origin: *');
        header('Content-Type:application/json; charset=utf-8');
        
        // 测试
        //echo accessEncrypt(5, 292070, time(), '50c31728df61f33592189f80bd3d9a0f', $this->accessKey);die;
        
        // 控制器名
        $controller = request()->controller();
        
        // 获取方法名
        $action = request()->action();
        
        // 不需要做入口验证的方法
        $noVerifyFunction = [
            'weixin/loginapplet', 'weixin/wxnotify', 'weixin/wxnotifytest', 'index/index', 'file/uploadimgtotencentcos', 
            'file/upload', 'file/uploadfile', 'file/upload',
            // 第三方
            'applet/accreditnotice',
            'world/index',
            'world/competition',
            'world/advanced_graph',
            'world/integral'
            
        ];
        
        $post = request()->only('mstr', 'post');
        
        if ( ! isset($post['mstr'])) {
            $post['mstr'] = '';
        }
        
        $data = [];
        $data['action'] = $action;
        $data['controller'] = $controller;
        $data['no_verify_func'] = $noVerifyFunction;
        $data['access_key'] = $this->accessKey;
        $data['mstr'] = $post['mstr'];
        
        // 入口验证
        $this->accessData = accessVerify($data);
    }
    
    //分享群id解密--lixue
    public function getDecrypt($session_key,$encryptedData,$iv,$apd)
    {
        include_once EXTEND_PATH . 'WxbizDataCrypt/wxBizDataCrypt.php';
        //require_once VENDOR_PATH . 'WxAes/wxBizDataCrypt.php';
    
        $appid = $apd;

        $pc = new \WXBizDataCrypt($appid, $session_key);
        $errCode = $pc->decryptData($encryptedData, $iv, $data );

        if ($errCode == 0) {
            $res = json_decode($data,true);
            return $res;
        }else{
            return FALSE;
        }
    }
    

    //域名跳转
    public function game_img($img)
    {
        $image = 'http://osssnxl.5iape.com/'.$img;
        return $image;
    }
    
    //世界杯域名跳转
    public function world_img($img)
    {
        $image = 'https://sndzza.5iape.com/'.$img;
        return $image;
    }
    
    
    
    
    
    
    
    
    
}